package com.blog.controller;

import com.blog.Utils.Result;
import com.blog.annotion.LoginAnnotatio;
import com.blog.bean.domain.GptMessage;
import com.blog.bean.dto.GptDTO;
import com.blog.bean.vo.GptVO;
import com.blog.service.ChatGptDirectoryService;
import com.blog.service.ChatGptService;
import com.blog.service.GptService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author 任浩
 * @version 1.0
 */

@RestController
@RequestMapping("/myGPT")
public class GptController {

    @Autowired
    private GptService gptService;

    @Autowired
    private ChatGptDirectoryService chatGptDirectoryService;

    @Autowired
    private ChatGptService chatGptService;


    /**
     * 和ai对话的接口。
     * @return
     */

    //todo  对于当前接口我们应当做一个限流的措施。
    @PostMapping("/chat")
    @LoginAnnotatio
    public Result<GptVO> getChatGpt(@RequestBody GptDTO chatData){
        return Result.success(gptService.getChatGpt(chatData));
    }

    /**
     * 获取聊天记录的列表。
     * @return
     */
    @GetMapping("/list")
    @LoginAnnotatio
    public Result getChatList(){
        return Result.success(chatGptDirectoryService.getList());
    }

    /**
     * 搜索聊天记录列表
     * @return
     */
    @GetMapping("/search")
    @LoginAnnotatio
    public Result searchChatList(@RequestParam("title") String title){
        return Result.success(chatGptDirectoryService.search(title));
    }

    /**
     * 根据id删除聊天目录。
     * @param id
     * @return
     */
    @PostMapping("/delete")
    @LoginAnnotatio
    public Result deleteById(@RequestParam("id") Integer id){
        return Result.success(chatGptDirectoryService.deleteById(id));
    }

    /**
     * 根据聊天记录id，获取相应的详细gpt数据
     * @param category
     * @return
     */
    @GetMapping("/getGptData")
    @LoginAnnotatio
    public Result getGptData(@RequestParam("category") Integer category){
        return Result.success(chatGptService.getGptData(category));
    }

    @GetMapping
    @LoginAnnotatio
    public Result getGPTToken(){
        return Result.success(gptService.getGPTToken());
    }

}
